<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Home\Controller;
use OT\DataDictionary;
header("Content-type: text/html; charset=utf-8");
/**
 * 运营系统控制器
 */
class OperateController extends HomeController
{

    /**
     * 检测是否登录
     * */
    public function _initialize()
    {
        if(empty(session('user_id'))){
            header('Location: ' . U('/Home/Login/Login'));exit;
        }else{
            //再来判断权限
            if(session('Supertube')==1){
                //超管 拥有所有权限
                //看商户有没有认证 没有认证就跳转去认证页面
                $action_name=ACTION_NAME;
                if($action_name == contentStatistics || $action_name == ContentStatistics){
                    $iid=session('iid');
                    $api_status=M('institution')->where("id=$iid")->getField('api_status');

                    if($api_status !=1){
                        return $this->error('未认证，跳转到认证页面',U('Mechanism/setInfo',array('menu'=>1)));
                    }
                }
            }else{
                $id=session('user_id');//不是超管的时候 user_id是account_number的主键ID
                $jurisdiction=M('account_number')->where("id=$id")->getField('jurisdiction');
                $action_name=ACTION_NAME;
                if($action_name == contentStatistics || $action_name == ContentStatistics){
                    //访问数据统计
                    $domain = strstr($jurisdiction, ',15,');
                    if(!$domain){
                        $this->error('没有访问权限');
                    }else{
                        //看商户有没有认证 没有认证就跳转去认证页面
                        $iid=session('iid');
                        $api_status=M('institution')->where("id=$iid")->getField('api_status');
                        if($api_status !=1){
                            return $this->error('未认证，跳转到认证页面',U('Mechanism/setInfo',array('menu'=>1)));
                        }
                    }
                }elseif($action_name == liveCourse || $action_name == LiveCourse){
                    //排行榜
                    $domain = strstr($jurisdiction, ',16,');
                    if(!$domain){
                        $this->error('没有访问权限');
                    }
                }elseif($action_name == videoCourse || $action_name == VideoCourse){
                    //线索列表
                    $domain = strstr($jurisdiction, ',17,');
                    if(!$domain){
                        $this->error('没有访问权限');
                    }
                }elseif($action_name == faceCourse || $action_name == FaceCourse){
                    //线索列表
                    $domain = strstr($jurisdiction, ',18,');
                    if(!$domain){
                        $this->error('没有访问权限');
                    }
                }
            }
        }
    }
    //内容统计
    public function content_statisticstzb(){
        //直播课
        $map['uid']=session('user_id');
        $map['iid']=session('iid');
        $iid=session('iid');
        //已结束的开播 也就是累计开播
        $map['status']=3;
        $count=M('live_course')->where($map)->count();
        $this->assign('count',$count);
        //预开播
        $map['status']=1;
        $pre_count=M('live_course')->where($map)->count();
        $this->assign('pre_count',$pre_count);

        //点播课 也就是在线课程
        //总课程数
        $con['iid']=session('iid');
        $vedio_count=M('video_course')->where($con)->count();
        $this->assign('video_count',$vedio_count);
        //购买数 在线课程
        //我觉得teach_user_video_course表是购买在线课程记录表 但是这个表没有绑定机构
        $user_video_count=M('user_video_course a')->join('teach_video_course b on a.vc_id=b.id')->where("b.iid=$iid")->count();
        $this->assign('user_video_count',$user_video_count);

        //面授课
        //面授课总量
        $face_count=M('face_course')->where("iid=$iid")->count();
        $this->assign('face_count',$face_count);
        //面授课报名数 teach_signup_ranking报名排名
        // M('teach_signup_ranking')->where()
    }


    /**
     * Mr.Jiang
     * 直播课管理列表
     */
    public function liveCourse()
    {   
        $map['iid']=session('iid');
        $_REQUEST['name']?$map['name']=array('like',"%$_REQUEST[name]%"):'';
        $_REQUEST['status']?$map['status']=$_REQUEST['status']:'';
        $this->assign('name',$_REQUEST['name']);
        $this->assign('status',$_REQUEST['status']);
        if($_REQUEST['start_time'] && $_REQUEST['end_time']){
            $btime=strtotime($_REQUEST['start_time']);
            $etime=strtotime($_REQUEST['end_time']." 23:59:59");
            $map['create_time']=array('between',"$btime,$etime");  
            $this->assign('start_time',$_REQUEST['start_time']);
            $this->assign('end_time',$_REQUEST['end_time']);
        }
        $count = M('live_course')->where($map)->count();
        // print_r($map);die;
        $Page = new \Think\Page($count, 10,$_REQUEST);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $list = M('live_course')->limit($Page->firstRow . ',' . $Page->listRows)->where($map)->order('id desc')->select();
        foreach($list as $k=>$v){
            $list[$k]['img']=M('picture')->where("id=$v[img]")->getfield('path');
            if($v['status']==0){
                $list[$k]['state']='申请中';
            }elseif($v['status']==1){
                $list[$k]['state']='预开播';
            }elseif($v['status']==2){
                $list[$k]['state']='直播中';
            }else{
                $list[$k]['state']='已结束';
            }
            $list[$k]['create_time']=date('Y-m-d H:i:s',$v['create_time']);
            $list[$k]['live_time']=date('Y-m-d H:i:s',$v['live_time']);
            // $list[$k]['real_live_duration']=strtotime($v['real_live_duration']);
        }
        $this->assign('_list', $list);
        $show = $Page->show();// 分页显示输出
        $this->assign("_page", $show);

        $this->meta_title = '直播课管理';
        $this->assign('cur','直播课管理');
        $this->display();
    }

    /**
     * Mr.Jiang
     * 新开直播课
     */
    public function addLiveCourse()
    {
        if (IS_POST) {
            // print_r($_REQUEST['live_time']);die;
            $data['iid'] = session('iid');
            // $data['one_type_id'] = $_REQUEST['one_type_id'];
            // $data['two_type_id'] = $_REQUEST['two_type_id'];
            $data['name'] = $_REQUEST['name'];
            $data['img'] = $_REQUEST['img'];
            $data['desc'] = $_REQUEST['desc'];
            $data['minute'] = $_REQUEST['minute'];
            $data['price'] = $_REQUEST['price'];
            $data['cost_price'] = $_REQUEST['cost_price'];
            $data['teacher_id'] = $_REQUEST['teacher_id'];
            
            $data['live_time'] = strtotime($_REQUEST['live_time']);
            $data['live_time_date'] = date('Y-m-d H:i:s',$data['live_time']);
            // $data['live_time_slot'] = $_REQUEST['live_time_slot'];
            //根据开播时间算出时间段
            $h=date('H:i',$data['live_time']);
            $s=$_REQUEST['minute']*60;

            // $jj=date('Y-m-d',time());

            $mm=$data['live_time']+$s;

            $gg=date('H:i',$mm);
            // print_r($gg);die;
            $data['live_time_slot']=$h.'~'.$gg;

            $time = time();
            $data['update_time'] = $time;
            $data['create_time'] = $time;
            // print_r($data);die;
            $result = D('live_course')->add($data);
            if ($result) {
                if(session('Supertube')==2){
                    //不记录超管的 只记录这种有权限的
                    $data['account_id']=session('user_id');
                    $data['create_time']=time();
                    $data['ip_address']=$_SERVER["REMOTE_ADDR"];
                    $data['content']='直播课管理'.'-'.'新增';
                    M('account_log')->add($data);
                }
                $data['result'] = 1;
                echo json_encode($data);
                exit;
            } else {
                $data['result'] = 2;
                echo json_encode($data);
                exit;   
            }
        } else {
            //父级分类
            // $parent = D('live_course_type')->where(array('pid' => 0))->order('id desc')->select();
            // //子级分类
            // $child = D('live_course_type')->where(array('pid' => $parent[0]['id']))->order('id desc')->select();

            //老师
            $iid = session('iid');
            // $teach = D('ucenter_member')->where(array('user_type' => 4, 'iid' => $iid))->order('id desc')->select();
            $teach=M('teacher')->where("iid=$iid")->select();

            //抽成比例
            $bl=10;
            $this->assign('bl', $bl);
            // $this->assign('parent', $parent);
            // $this->assign('child', $child);
            $this->assign('teach', $teach);
            $this->assign('cur','直播课管理');
            $this->display();
        }
    }

    //直播课详情 tzb
    public function live_detail(){
        $info=M('live_course')->where("id=$_REQUEST[id]")->find();
        $info['teach_name']=M('ucenter_member')->where("id=$info[teacher_id]")->getfield('username');
        $info['mobile']=M('ucenter_member')->where("id=$info[teacher_id]")->getfield('mobile');
        $info['img']=M('picture')->where("id=$info[img]")->getfield('path');

        //报名人数
        $map['iid']=session('iid');
        $iid=session('iid');
        $map['live']=1;
        $count = M('signup_ranking')->where($map)->count();
        $Page = new \Think\Page($count, 10,$map);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $list = M('signup_ranking')->limit($Page->firstRow . ',' . $Page->listRows)->where($map)->order('id desc')->select();
        foreach($list as $k=>$v){
            $list[$k]['create_time']=date('Y-m-d H:i:s',$v['create_time']);
            $uid=M('order')->where("id=$v[order_id] && iid=$iid")->getfield('uid');
            $list[$k]['name']=M('ucenter_member')->where("id=$uid")->getfield('username');
        }
        $this->assign('_list', $list);
        $show = $Page->show();// 分页显示输出
        $this->assign("_page", $show);

        $this->assign('info',$info);
        $this->assign('cur','直播课管理');
        $this->display();
    }
    //开播
    public function live_show(){
        $roomID = '123456';
        $this->assign('roomID', $roomID);
        $config = api('Config/lists');
        $SDKAppID = $config['YUNSDKAPPID'];
        // print_r($SDKAppID);die;
        $this->assign('SDKAppID', $SDKAppID);
        $userID = 'Dave';
        $this->assign('userID', $userID);
        $liveDomainName = 'administrator';
        $this->assign('liveDomainName', $liveDomainName);
        $streamid = '27240_654321';
        $this->assign('streamid', $streamid);
        $userSig = getUserSig($userID);
        echo $userSig;
        $this->assign('userSig', $userSig);
        $this->assign('cur','直播课管理');
        $this->display();
    }
    //删除直播课
    public function live_del(){
        $id=$_REQUEST['id'];
        $res=M('live_course')->where("id=$id")->delete();
        if($res){
            if(session('Supertube')==2){
                //不记录超管的 只记录这种有权限的
                $data['account_id']=session('user_id');
                $data['create_time']=time();
                $data['ip_address']=$_SERVER["REMOTE_ADDR"];
                $data['content']='直播课管理'.'-'.'删除';
                M('account_log')->add($data);
            } 
            $this->success('成功',U('liveCourse'));
        }else{
            $this->error('失败');
        }

    }
    /**
     * Mr.Jiang
     * 面授课管理列表
     */
    public function faceCourse()
    {
        $map['iid']=session('iid');
        $map['is_del']=0;
        $_REQUEST['iid']=session('iid');
        $_REQUEST['name']?$map['name']=array('like',"%$_REQUEST[name]%"):'';
        $_REQUEST['is_upper']?$map['is_upper']=$_REQUEST['is_upper']:'';
        if($_REQUEST['start_time'] && $_REQUEST['end_time']){
            $btime=strtotime($_REQUEST['start_time']);
            $etime=strtotime($_REQUEST['end_time']." 23:59:59");
            $map['create_time']=array('between',"$btime,$etime");  
        }

        if(is_numeric($_REQUEST['is_upper']) === false){
            // $_REQUEST['is_upper']=11;
        }elseif($_REQUEST['is_upper']){
            $map['is_upper']=$_REQUEST['is_upper'];
        }else{
            $map['is_upper']=array('eq',0);
        }

        
        $count = M('face_course')->where($map)->count();
        $Page = new \Think\Page($count, 10,$_REQUEST);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $list = M('face_course')->limit($Page->firstRow . ',' . $Page->listRows)->where($map)->order('id desc')->select();
        foreach($list as $k=>$v){
            if($v['img']){
                $list[$k]['img']=M('picture')->where("id=$v[img]")->getfield('path');
            }else{
                $list[$k]['img']='';
            }
            
            $list[$k]['end_enlist_time']=date('Y-m-d',$v['end_enlist_time']);
            $province=M('province')->where("province_id=$v[province_id]")->getfield('name');
            $city=M('city')->where("city_id=$v[city_id]")->getfield('name');
            $area=M('area')->where("area_id=$v[area_id]")->getfield('name');
            $list[$k]['address_detail']=$province.$city.$area.$v['address'];
        }
        if(is_numeric($_REQUEST['is_upper']) === false){
            $_REQUEST['is_upper']=11;
        }else{
            
        }
        $this->assign('msg', $_REQUEST);
        $this->assign('_list', $list);
        $show = $Page->show();// 分页显示输出
        $this->assign("_page", $show);

        $this->meta_title = '面授课管理';
        $this->assign('cur','面授课管理');
        $this->display();
    }
    //面授课详情
    public function face_detail(){
        $iid=session('iid');
        $id=$_REQUEST['id'];

        $info=M('faceCourse')->where("id=$id")->find();

        $info['img']=M('picture')->where("id=$info[img]")->getfield('path');
        $info['end_enlist_time']=date('Y-m-d',$info['end_enlist_time']);
        $info['one_type_name']=M('face_course_type')->where("id=$info[one_type_id]")->getfield('name');
        $info['two_type_name']=M('face_course_type')->where("id=$info[two_type_id]")->getfield('name');
        $province=M('province')->where("province_id=$info[province_id]")->getfield('name');
        $city=M('city')->where("city_id=$info[city_id]")->getfield('name');
        $area=M('area')->where("area_id=$info[area_id]")->getfield('name');
        $info['address_detail']=$province.$city.$area.$info['address'];

        // $t_list=explode(',', $info['teacher_ids']);

        // foreach($t_list as $k=>$v){

        //     $h[$k]['username']=M('ucenter_member')->where("id=$v")->getfield('username');
        //     $h[$k]['mobile']=M('ucenter_member')->where("id=$v")->getfield('mobile');
        // }

        //老师要取teacher表

        $t_list=explode(',', $info['teacher_ids']);
        // print_r($t_list);die;
        if($t_list){
            foreach($t_list as $k=>$v){
                $uid=M('teacher')->where("id=$v")->getField('uid');
                $h[$k]['username']=M('ucenter_member')->where("id=$uid")->getfield('username');
                $h[$k]['mobile']=M('ucenter_member')->where("id=$uid")->getfield('mobile');
            }
        }


// print_r($h);die;
        $zhou=json_decode($info['study_time'],true);
        $catalog=json_decode($info['catalog'],true);
        // print_r($catalog);die;

        $map['a.face']=1;
        $map['a.iid']=session('iid');
        $map['b.to_id']=$id;
        $info['enlist_count']=M('signup_ranking a')->join('left join teach_vice_order b on a.order_id=b.order_id')->limit($Page->firstRow . ',' . $Page->listRows)->where($map)->order('a.id desc')->field('a.*')->count();
        // $list = M('signup_ranking')->limit($Page->firstRow . ',' . $Page->listRows)->where($map)->order('id desc')->select();
        $list = M('signup_ranking a')->join('left join teach_vice_order b on a.order_id=b.order_id')->limit($Page->firstRow . ',' . $Page->listRows)->where($map)->order('a.id desc')->field('a.*')->select();
        // echo '<pre>';print_r($list);die;
        foreach($list as $k=>$v){
            $list[$k]['create_time']=date('Y-m-d H:i:s',$v['create_time']);
            $uid=M('order')->where("id=$v[order_id] && iid=$iid")->getfield('uid');
            $list[$k]['name']=M('ucenter_member')->where("id=$uid")->getfield('username');
        }
        $this->assign('_list', $list);
        $this->assign('catalog',$catalog);
        $this->assign('zhou',$zhou);
        $this->assign('t_list',$h);
        $this->assign('info',$info);
        $this->assign('cur','面授课管理');
        $this->display();
    }
    /**
     * Mr.Jiang
     * 新开面授课
     */
    public function addFaceCourse()
    {
        if (IS_POST) {
            // echo '<pre>';print_r($_REQUEST);die;
            // echo '<pre>';print_r($_REQUEST);die;
            $head_word=$_REQUEST['head_word'];
            // print_r($head_word);die;
            $subsection_title=$_REQUEST['subsection_title'];
            $data['count']=count($subsection_title);
            $li=$_REQUEST['li'];
            $ll=explode(',', $li);
            foreach($ll as $k=>$v){
                $sub=array();
                for($i=0;$i<$v;$i++){
                        
                        $sub[]=$subsection_title[$i];
                        
                        unset($subsection_title[$i]);

                }
                $j[$k]['head_word']=$head_word[$k];
                $j[$k]['subsection_title']=$sub;
                $subsection_title=array_merge($subsection_title);
                
            }

            foreach($j as $k=>$v){
                foreach($v['subsection_title'] as $kk=>$vv){
                    if(!$vv){
                        unset($j[$k]['subsection_title'][$kk]);
                    }
                }
            }
 
            $data['catalog']=json_encode($j);
            $data['iid'] = session('iid');
            $data['one_type_id'] = $_REQUEST['one_type_id'];
            $data['two_type_id'] = $_REQUEST['two_type_id'];
            $data['name'] = $_REQUEST['name'];
            $data['img'] = $_REQUEST['img'];
            $data['price'] = $_REQUEST['price'];
            $data['desc'] = $_REQUEST['desc'];
            // $data['catalog'] = $_REQUEST['catalog'];
            $data['enlist_count'] = $_REQUEST['enlist_count'];
            $data['end_enlist_time'] = strtotime($_REQUEST['end_enlist_time']);
            $data['province_id'] = $_REQUEST['province_id'];
            $data['city_id'] = $_REQUEST['city_id'];
            $data['area_id'] = $_REQUEST['area_id'];
            $data['address'] = $_REQUEST['address'];
            // $data['study_time'] = $_REQUEST['study_time'];

            $zhou=$_REQUEST['zhou'];
            $sj=$_REQUEST['sj'];
            
            $zb=array();
            foreach($zhou as $k=>$v){
                $zb[$k]['date']=$v;
                $zb[$k]['time']=$sj[$k];
            }
            $data['study_time']=json_encode($zb);
            $teach=$_REQUEST['teach_id'];
            $teacher_ids=array();
            foreach($teach as $k=>$v){
                if($k==0){
                    $teacher_ids=$v;
                }else{
                    $teacher_ids.=','.$v;
                }
                
            }
            $data['teacher_ids'] = $teacher_ids;

            if ($data['name'] == '') {
                $this->error("请输入课程名称");
            }

            if (empty($data['img'])) {
                $this->error("请上传封面");
            }
            $data['start_date'] = $_REQUEST['start_date'];
            $data['end_date'] = $_REQUEST['end_date'];
            
            $data['is_upper'] = 1;
            $time = time();
            $data['update_time'] = $time;
            $data['create_time'] = $time;
            $result = D('face_course')->add($data);
            if ($result) {
                if(session('Supertube')==2){
                    //不记录超管的 只记录这种有权限的
                    $data['account_id']=session('user_id');
                    $data['create_time']=time();
                    $data['ip_address']=$_SERVER["REMOTE_ADDR"];
                    $data['content']='面授课管理'.'-'.'新增';
                    M('account_log')->add($data);
                }
                $this->success("新增成功", U('faceCourse'));
            } else {
                $this->error("新增失败");
            }
        } else {
            $province = D('province')->select();
            $city = D('city')->where(array('province_id' => $province[0]['province_id']))->select();
            $area = D('area')->where(array('city_id' => $city[0]['city_id']))->select();
            // echo '<pre>';print_r($city);die;
            //老师
            $iid = session('iid');
            // $teach = D('ucenter_member')->where(array('user_type' => 4, 'iid' => $iid))->order('id desc')->select();
            $teach=M('teacher a')->join('teach_ucenter_member b on a.uid=b.id')->where("a.iid=$iid")->order('a.id desc')->field('a.id,b.username,b.mobile')->select();
            // print_r($teach);die;
            //一级分类
            $type_list=M('face_course_type')->where("pid=0")->select();
            $this->assign('type_list',$type_list);
            $this->assign('province', $province);
            $this->assign('city', $city);
            $this->assign('area', $area);
            $this->assign('teach', $teach);
            $this->assign('cur','面授课管理');
            $this->display();
        }
    }
    //得到省级 ID 获取市
    public function city_list(){
        $id=$_REQUEST['province_id'];
        $list['city']=M('city')->where("province_id=$id")->select();
        $list['area']=M('area')->where(array('city_id' => $list['city'][0]['city_id']))->select();
        return api_return(1, '信息获取成功', $list);
    }
        //得到市级 ID 获取区
    public function area_list(){
        $id=$_REQUEST['city_id'];
        $list=M('area')->where("city_id=$id")->select();
        return api_return(1, '信息获取成功', $list);
    }
    public function teach_list(){
        $iid=session('iid');
        // $list = D('ucenter_member')->where(array('user_type' => 4, 'iid' => $iid))->order('id desc')->select();
        $list=M('teacher a')->join('teach_ucenter_member b on a.uid=b.id')->where("a.iid=$iid")->order('a.id desc')->field('a.id,b.username,b.mobile')->select();
        return api_return(1, '信息获取成功', $list);
    }
    //获取二级分类
    public function two_type_list(){

        $pid = $_REQUEST['type_id'];

        $child = D('face_course_type')->where(array('pid' => $pid))->order('id desc')->select();


        return api_return(1, '信息获取成功', $child);
    }

    /**
     * Mr.Jiang
     * 面授课上下架
     */
    public function loadingAndUnloadingFaceCourse()
    {
        $id = $_REQUEST['id'];
        $is_upper = $_REQUEST['is_upper'];
        if ($is_upper == 1) {
            $msg = "上架";
        } else {
            $msg = "下架";
        }
        $result = D('face_course')->where(array('id' => $id))->save(array('is_upper' => $is_upper));
        if ($result) {
            $this->success($msg . "成功");
        } else {
            $this->error($msg . "失败");
        }
    }

    /**
     * Mr.Jiang
     * 删除面授课
     */
    public function delFaceCourse()
    {
        $id = $_REQUEST['id'];
        $faceCourse = D('face_course')->where(array('id' => $id))->find();
        if ($faceCourse['is_del'] == 1) {
            $this->error("当前数据已被删除");
        }
        $result = D('face_course')->where(array('id' => $id))->save(array('is_del' => 1));
        if ($result) {
            if(session('Supertube')==2){
                //不记录超管的 只记录这种有权限的
                $data['account_id']=session('user_id');
                $data['create_time']=time();
                $data['ip_address']=$_SERVER["REMOTE_ADDR"];
                $data['content']='面授课管理'.'-'.'删除';
                M('account_log')->add($data);
            }
            $this->success("删除成功");
        } else {
            $this->error("删除失败");
        }
    }

    /**
     * Mr.Jiang
     * 视频课管理
     */
    public function videoCourse()
    {   
        $map['iid']=session('iid');
        $map['is_del']=0;
        $_REQUEST['iid']=session('iid');
        $_REQUEST['name']?$map['name']=array('like',"%$_REQUEST[name]%"):'';
        $_REQUEST['two_type_id']?$map['two_type_id']=$_REQUEST['two_type_id']:'';
        // $_REQUEST['is_upper']?$map['is_upper']=$_REQUEST['is_upper']:'';
        $_REQUEST['is_recommend']?$map['is_recommend']=$_REQUEST['is_recommend']:'';
        $count = M('video_course')->where($map)->count();
        // print_r($map);die;
        if(is_numeric($_REQUEST['is_upper']) === false){
            // $_REQUEST['is_upper']=11;
        }elseif($_REQUEST['is_upper']){
            $map['is_upper']=$_REQUEST['is_upper'];
        }else{
            $map['is_upper']=array('eq',0);
        }
        $Page = new \Think\Page($count, 10,$_REQUEST);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $list = M('video_course')->limit($Page->firstRow . ',' . $Page->listRows)->where($map)->order('id desc')->select();
        foreach($list as $k=>$v){
            $list[$k]['img']=M('picture')->where("id=$v[img]")->getfield('path');
            $info=M('video_book')->where("video_id=$v[id]")->find();
            if($info){
                $list[$k]['is_book']='是';
            }else{
                $list[$k]['is_book']='否';
            }
            if($v['is_recommend']==1){
                $list[$k]['recommend']='未推荐';
            }else{
                $list[$k]['recommend']='已推荐';
            }
            if($v['is_upper']==1){
                $list[$k]['upper']='上架';
            }else{
                $list[$k]['upper']='下架';
            }
            //课程类型我现在取得是分类 好像不是
            $list[$k]['type_name']=M('video_course_type')->where("id=$v[two_type_id]")->getfield('name');
            //多少集
            $list[$k]['count']=M('video_tree')->where("vc_id=$v[copy_id]")->count();
            //累计购买数量

            $list[$k]['count_number']=M('order a')->join('teach_vice_order b on a.id=b.order_id')->where("a.iid=$_REQUEST[iid] && a.type=3 && b.to_id=$v[id]")->count();
            // print_r($list[$k]['count_number']);die;
        }
        $platform_list=M('video_course')->where("iid=0 && is_del=0")->select();
        foreach($platform_list as $k=>$v){
            $find=M('video_course')->where("iid=$map[iid] && copy_id=$v[id]")->find();
            if($find){
                unset($platform_list[$k]);
            }else{
                $platform_list[$k]['one_type_name']=M('video_course_type')->where("id=$v[one_type_id]")->getfield('name');
                $platform_list[$k]['two_type_name']=M('video_course_type')->where("id=$v[two_type_id]")->getfield('name');
                $platform_list[$k]['count']=M('video_tree')->where("vc_id=$v[id]")->count();
                $platform_list[$k]['img']=M('picture')->where("id=$v[img]")->getField('path');
            }

        }
        // echo '<pre>';print_r($platform_list);die;
        if(is_numeric($_REQUEST['is_upper']) === false){
            $_REQUEST['is_upper']=11;
        }else{
            
        }
        $this->assign('platform_list', $platform_list);
        $type_list=M('video_course_type')->where("pid=0")->select();
        $this->assign('type_list',$type_list);
        //选课售卖
        //选择课程类型
        $t_list=M('video_course_type')->where("pid !=0")->select();
        $this->assign('t_list', $t_list);
        $this->assign('_list', $list);
        $show = $Page->show();// 分页显示输出
        $this->assign("_page", $show);
        $this->assign('msg',$_REQUEST);
        $this->meta_title = '视频课管理';
        $this->assign('cur','视频课管理');
        $this->display();
    }

    public function getChildType()
    {
        $pid = $_REQUEST['pid'];

        $child = D('video_course_type')->where(array('pid' => $pid))->order('id desc')->select();


        return api_return(1, '信息获取成功', $child);
    }

        public function getCourse()
    {
        $_REQUEST['type_id']?$type_id = $_REQUEST['type_id']:'';
        $iid=session('iid');
        //新加一个课程名称搜索
        $_REQUEST['name']?$name=array('like',"%$_REQUEST[name]%"):$name='';

        if($name){
            $course = D('video_course')->where(array('iid' => 0, 'two_type_id' => $type_id,'name'=>$name))->order('id desc')->select();
        }else{
            $course = D('video_course')->where(array('iid' => 0, 'two_type_id' => $type_id))->order('id desc')->select();
        }
            
        if($_REQUEST['type']==3){
            //从预售搜索进来
            foreach($course as $k=>$v){
                $find=M('video_course')->where("iid=$iid && copy_id=$v[id]")->find();
                if($find){
                    unset($course[$k]);
                }
            }
        }
        //tzb 处理下图片
        foreach($course as $k=>$v){
            $course[$k]['img']=M('picture')->where("id=$v[img]")->getfield('path');
            $course[$k]['one_type_name']=M('video_course_type')->where("id=$v[one_type_id]")->getfield('name');
            $course[$k]['two_type_name']=M('video_course_type')->where("id=$v[two_type_id]")->getfield('name');
            $course[$k]['count']=M('video_tree')->where("vc_id=$v[id]")->count();
        }
        
        return api_return(1, '信息获取成功', $course);
    }
    //加入预售
    public function pre_sale(){
        $id = $_REQUEST['id'];
        // $is_upper = $_REQUEST['is_upper'];
        // if ($is_upper == 1) {
        //     $msg = "上架";
        // } else {
        //     $msg = "下架";
        // }
        $data=M('video_course')->where("id=$id")->find();
        $data['iid']=session('iid');
        $data['copy_id']=$data['id'];
        unset($data['id']);
        $result = D('video_course')->where(array('id' => $id))->add($data);
        if ($result) {
            if(session('Supertube')==2){
                //不记录超管的 只记录这种有权限的
                $data['account_id']=session('user_id');
                $data['create_time']=time();
                $data['ip_address']=$_SERVER["REMOTE_ADDR"];
                $data['content']='视频课管理'.'-'.'选课售卖';
                M('account_log')->add($data);
            }
            $this->success('加入' . "成功",U('videoCourse'));
        } else {
            $this->error('加入' . "失败",U('videoCourse'));
        }
    }
    //修改加个 过期日期
    public function overdue(){
        $data=$_REQUEST;
        $res=M('video_course')->save($data);
        if($res){
            if(session('Supertube')==2){
                //不记录超管的 只记录这种有权限的
                $data['account_id']=session('user_id');
                $data['create_time']=time();
                $data['ip_address']=$_SERVER["REMOTE_ADDR"];
                $data['content']='视频课管理'.'-'.'修改';
                M('account_log')->add($data);
            }
            return api_return(1, '修改成功');
        }else{
            return api_return(2, '修改失败');
        }
        
    }
    /**
     * Mr.Jiang
     * 视频课上下架
     */
    public function loadingAndUnloadingVideoCourse()
    {
        $id = $_REQUEST['id'];
        $is_upper = $_REQUEST['is_upper'];
        if ($is_upper == 1) {
            $msg = "上架";
        } else {
            $msg = "下架";
        }
        $result = D('video_course')->where(array('id' => $id))->save(array('is_upper' => $is_upper));
        if ($result) {
            $this->success($msg . "成功");
        } else {
            $this->error($msg . "失败");
        }
    }
    //tzb 推荐
    public function recommend()
    {
        $id = $_REQUEST['id'];
        $is_recommend = $_REQUEST['is_recommend'];
        if ($is_recommend == 2) {
            $msg = "推荐";
        } else {
            $msg = "取消推荐";
        }
        $result = D('video_course')->where(array('id' => $id))->save(array('is_recommend' => $is_recommend));
        if ($result) {
            $this->success($msg . "成功");
        } else {
            $this->error($msg . "失败");
        }
    }
    //点播客详情 tzb
    public function video_detail(){
        $iid=session('iid');
        $id=$_REQUEST['id'];
        $info=M('video_course')->where("id=$id")->find();
        $info['img']=M('picture')->where("id=$info[img]")->getfield('path');
        $info['count']=M('video_tree')->where("vc_id=$info[id]")->count();
        $info['overdue']=date('Y-m-d',$info['overdue']);
        $info['one_type_name']=M('video_course_type')->where("id=$info[one_type_id]")->getfield('name');
        $info['two_type_name']=M('video_course_type')->where("id=$info[two_type_id]")->getfield('name');
        $list=M('video_tree')->where("vc_id=$info[copy_id] && pid=0")->select();
        foreach($list as $k=>$v){
            $list[$k]['sub']=M('video_tree')->where("pid=$v[id]")->select();
        }
        // echo '<pre>';print_r($list);die;


        $map['a.video']=1;
        $map['a.iid']=session('iid');
        $map['b.to_id']=$id;
        $info['enlist_count']=M('signup_ranking a')->join('left join teach_vice_order b on a.order_id=b.order_id')->limit($Page->firstRow . ',' . $Page->listRows)->where($map)->order('a.id desc')->field('a.*')->count();
        // $list = M('signup_ranking')->limit($Page->firstRow . ',' . $Page->listRows)->where($map)->order('id desc')->select();
        $lists = M('signup_ranking a')->join('left join teach_vice_order b on a.order_id=b.order_id')->limit($Page->firstRow . ',' . $Page->listRows)->where($map)->order('a.id desc')->field('a.*')->select();
        foreach($lists as $k=>$v){
            $lists[$k]['create_time']=date('Y-m-d H:i:s',$v['create_time']);
            $uid=M('order')->where("id=$v[order_id] && iid=$iid")->getfield('uid');
            $lists[$k]['name']=M('ucenter_member')->where("id=$uid")->getfield('username');
        }
        $this->assign('lists', $lists);

        $this->assign('list',$list);
        $this->assign('info',$info);
        $this->assign('cur','视频课管理');
        $this->display();
    }
    /**
     * Mr.Jiang
     * 删除视频课
     */
    public function delVideoCourse()
    {
        $id = $_REQUEST['id'];
        $faceCourse = D('video_course')->where(array('id' => $id))->find();
        if ($faceCourse['is_del'] == 1) {
            $this->error("当前数据已被删除");
        }
        $result = D('video_course')->where(array('id' => $id))->save(array('is_del' => 1));
        if ($result) {
            if(session('Supertube')==2){
                //不记录超管的 只记录这种有权限的
                $data['account_id']=session('user_id');
                $data['create_time']=time();
                $data['ip_address']=$_SERVER["REMOTE_ADDR"];
                $data['content']='视频课管理'.'-'.'删除';
                M('account_log')->add($data);
            }
            $this->success("删除成功");
        } else {
            $this->error("删除失败");
        }
    }
    public function contentStatistics()
    {
        $iid = session('iid');
        //直播课统计，累计开播、预开播
        $cumulative_live_map['status'] = array(array('eq', 2), array('eq', 3), 'OR');
        $cumulative_live_map['is_del'] = array('eq', 0);
        $cumulative_live_map['iid'] = array('eq', $iid);
        $cumulative = D('live_course')->where($cumulative_live_map)->count();
        $this->assign('cumulative', $cumulative);

        $pre_live_map['status'] = array('eq', 1);
        $pre_live_map['is_del'] = array('eq', 0);
        $pre_live_map['iid'] = array('eq', $iid);
        $pre = D('live_course')->where($pre_live_map)->count();
        $this->assign('pre', $pre);

        //点播课统计，总课程数、购买数
        $total_video_map['is_del'] = array('eq', 0);
        $total_video_map['is_upper'] = array('eq', 1);
        $total_video_map['iid'] = array('eq', $iid);
        $total = D('video_course')->where($total_video_map)->count();
        $this->assign('total', $total);

        // $order_map['a.status'] = array('eq', 1);
        $order_map['a.iid'] = array('eq', $iid);
        $order_map['a.type'] = array('eq', 3);
        $order = D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($order_map)->count();
        $this->assign('order', $order);

        //面授课统计，开课数、报名数
        $class_map['iid'] = array('eq', $iid);
        $class_map['status'] = array('eq', 2);
        $class_map['is_upper'] = array('eq', 1);
        $class_map['is_del'] = array('eq', 0);
        $class = D('face_course')->where($class_map)->count();
        $this->assign('class', $class);

        // $signup_map['a.status'] = array('eq', 4);
        $signup_map['a.iid'] = array('eq', $iid);
        $signup_map['a.type'] = array('eq', 2);
        $signup = D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($signup_map)->count();
        $this->assign('signup', $signup);

        //折线图统计



        $search=$_REQUEST['search']?$_REQUEST['search']:1;
        $_REQUEST['category']?$category=$_REQUEST['category']:$category=1;
        $this->assign('category',$category);
        $this->assign('search',$search);

        if($search==1){
            //今天
            $line_time = date('m-d',time());
            $this->assign('line_time',$line_time);

            //开课数
            $bbtime=date('Y-m-d',time());//今天
            $ebtime=date('Y-m-d',strtotime("+1 day"));//明天
            //这个时间查询以前是日期查询 不是时间戳  要改一下
            $btime=strtotime($bbtime);
            $etime=strtotime($ebtime);

            if($category==1){
                //面授课
                $class_map['create_time'] = array('between',"$btime,$etime");   
                $grey= D('face_course')->where($class_map)->count();
                // print_r($red);die;
                //报名数
                $signup_map['a.create_time'] = array('between',"$btime,$etime");   
                $red= D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($signup_map)->count();
                
            }elseif($category==2){
                //点播 总课程数

                $total_video_map['create_time'] = array('between',"$btime,$etime");   
                $grey = D('video_course')->where($total_video_map)->count();
                //购买数
                $order_map['a.create_time']=array('between',"$btime,$etime");
                $red = D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($order_map)->count();
                // print_r($grey);die;
            }else{
                //直播 累计开播
                $cumulative_live_map['create_time'] = array('between',"$btime,$etime");   
                $grey = D('live_course')->where($cumulative_live_map)->count();
                //预计开播  估计这个统计有问题
                $pre_live_map['create_time'] = array('between',"$btime,$etime");   
                $red = D('live_course')->where($pre_live_map)->count();
            }
                            // print_r($red);die;
            $this->assign('red',$red);
            $this->assign('grey',$grey);
        }elseif($search==2){
            //昨天
            $line_time = date('m-d',strtotime("-1 day"));
            $this->assign('line_time',$line_time);


            //开课数
            $bbtime=date('Y-m-d',strtotime("-1 day"));//昨天
            $ebtime=date('Y-m-d',time());//今天
            
            //这个时间查询以前是日期查询 不是时间戳  要改一下
            $btime=strtotime($bbtime);
            $etime=strtotime($ebtime);

            if($category==1){
                //面授课
                $class_map['create_time'] = array('between',"$btime,$etime");   
                $grey= D('face_course')->where($class_map)->count();
                // print_r($red);die;
                //报名数
                $signup_map['a.create_time'] = array('between',"$btime,$etime");   
                $red= D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($signup_map)->count();
                // print_r($grey);die;
            }elseif($category==2){
                //点播 总课程数
                $total_video_map['create_time'] = array('between',"$btime,$etime");   
                $grey = D('video_course')->where($total_video_map)->count();
                //购买数
                $order_map['a.create_time']=array('between',"$btime,$etime");
                $red = D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($order_map)->count();
            }else{
                //直播 累计开播
                $cumulative_live_map['create_time'] = array('between',"$btime,$etime");   
                $grey = D('live_course')->where($cumulative_live_map)->count();
                //预计开播  估计这个统计有问题
                $pre_live_map['create_time'] = array('between',"$btime,$etime");   
                $red = D('live_course')->where($pre_live_map)->count();
            }
            $this->assign('red',$red);
            $this->assign('grey',$grey);
        }elseif($search==3){
            //最近七天
            $line_time = date('m-d',strtotime("-6 day"));
            $line_time .= ",".date('m-d',strtotime("-5 day"));
            $line_time .= ",".date('m-d',strtotime("-4 day"));
            $line_time .= ",".date('m-d',strtotime("-3 day"));
            $line_time .= ",".date('m-d',strtotime("-2 day"));
            $line_time .= ",".date('m-d',strtotime("-1 day"));
            $line_time .= ",".date('m-d',time());
            $this->assign('line_time',$line_time);


            if($category==1){
                //面授课
                //第七天
                $bbtime=date('Y-m-d',strtotime("-6 day"));//前第七天
                $ebtime=date('Y-m-d',strtotime("-5 day"));//
                //这个时间查询以前是日期查询 不是时间戳  要改一下
                $btime=strtotime($bbtime);
                $etime=strtotime($ebtime);
                $class_map['create_time'] = array('between',"$btime,$etime");   
                $grey_six= D('face_course')->where($class_map)->count();
                //报名数
                $signup_map['a.create_time'] = array('between',"$btime,$etime");   
                $red_six= D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($signup_map)->count();
                //第六天
                $bbtime=date('Y-m-d',strtotime("-5 day"));//前第六天
                $ebtime=date('Y-m-d',strtotime("-4 day"));//
                //这个时间查询以前是日期查询 不是时间戳  要改一下
                $btime=strtotime($bbtime);
                $etime=strtotime($ebtime);
                $class_map['create_time'] = array('between',"$btime,$etime");   
                $grey_five= D('face_course')->where($class_map)->count();
                //报名数
                $signup_map['a.create_time'] = array('between',"$btime,$etime");   
                $red_five= D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($signup_map)->count();
                //第五天
                $bbtime=date('Y-m-d',strtotime("-4 day"));//前第五天
                $ebtime=date('Y-m-d',strtotime("-3 day"));//
                //这个时间查询以前是日期查询 不是时间戳  要改一下
                $btime=strtotime($bbtime);
                $etime=strtotime($ebtime);
                $class_map['create_time'] = array('between',"$btime,$etime");   
                $grey_four= D('face_course')->where($class_map)->count();
                //报名数
                $signup_map['a.create_time'] = array('between',"$btime,$etime");   
                $red_four= D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($signup_map)->count();
                //第四天
                $bbtime=date('Y-m-d',strtotime("-3 day"));//前第四天
                $ebtime=date('Y-m-d',strtotime("-2 day"));//
                //这个时间查询以前是日期查询 不是时间戳  要改一下
                $btime=strtotime($bbtime);
                $etime=strtotime($ebtime);
                $class_map['create_time'] = array('between',"$btime,$etime");   
                $grey_three= D('face_course')->where($class_map)->count();
                //报名数
                $signup_map['a.create_time'] = array('between',"$btime,$etime");   
                $red_three= D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($signup_map)->count();
                //第三天
                $bbtime=date('Y-m-d',strtotime("-2 day"));//前第三天
                $ebtime=date('Y-m-d',strtotime("-1 day"));//
                //这个时间查询以前是日期查询 不是时间戳  要改一下
                $btime=strtotime($bbtime);
                $etime=strtotime($ebtime);
                $class_map['create_time'] = array('between',"$btime,$etime");   
                $grey_two= D('face_course')->where($class_map)->count();
                //报名数
                $signup_map['a.create_time'] = array('between',"$btime,$etime");   
                $red_two= D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($signup_map)->count();
                //第二天
                $bbtime=date('Y-m-d',strtotime("-1 day"));//昨天
                $ebtime=date('Y-m-d',time());//
                //这个时间查询以前是日期查询 不是时间戳  要改一下
                $btime=strtotime($bbtime);
                $etime=strtotime($ebtime);
                $class_map['create_time'] = array('between',"$btime,$etime");   
                $grey_one= D('face_course')->where($class_map)->count();
                //报名数
                $signup_map['a.create_time'] = array('between',"$btime,$etime");   
                $red_one= D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($signup_map)->count();
                //今天
                $bbtime=date('Y-m-d',time());//今天
                $ebtime=date('Y-m-d',strtotime("+1 day"));//明天
                            //这个时间查询以前是日期查询 不是时间戳  要改一下

                $btime=strtotime($bbtime);
                $etime=strtotime($ebtime);
                $class_map['create_time'] = array('between',"$btime,$etime");   
                $grey_zero= D('face_course')->where($class_map)->count();
                //报名数
                $signup_map['a.create_time'] = array('between',"$btime,$etime");   
                $red_zero= D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($signup_map)->count();

                //连接起来
                $grey=$grey_six.','.$grey_five.','.$grey_four.','.$grey_three.','.$grey_two.','.$grey_one.','.$grey_zero;
                $red=$red_six.','.$red_five.','.$red_four.','.$red_three.','.$red_two.','.$red_one.','.$red_zero;

            }elseif($category==2){
                //点播 总课程数
                //第七天
                $bbtime=date('Y-m-d',strtotime("-6 day"));//前第七天
                $ebtime=date('Y-m-d',strtotime("-5 day"));//
                //这个时间查询以前是日期查询 不是时间戳  要改一下
                $btime=strtotime($bbtime);
                $etime=strtotime($ebtime);
                $total_video_map['create_time'] = array('between',"$btime,$etime");   
                $grey_six = D('video_course')->where($total_video_map)->count();
                //购买数
                $order_map['a.create_time']=array('between',"$btime,$etime");
                $red_six = D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($order_map)->count();
                //第六天
                $bbtime=date('Y-m-d',strtotime("-5 day"));//前第六天
                $ebtime=date('Y-m-d',strtotime("-4 day"));//
                //这个时间查询以前是日期查询 不是时间戳  要改一下
                $btime=strtotime($bbtime);
                $etime=strtotime($ebtime);
                $total_video_map['create_time'] = array('between',"$btime,$etime");   
                $grey_five = D('video_course')->where($total_video_map)->count();
                //购买数
                $order_map['a.create_time']=array('between',"$btime,$etime");
                $red_five = D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($order_map)->count();
                //第五天
                $bbtime=date('Y-m-d',strtotime("-4 day"));//前第五天
                $ebtime=date('Y-m-d',strtotime("-3 day"));//
                //这个时间查询以前是日期查询 不是时间戳  要改一下
                $btime=strtotime($bbtime);
                $etime=strtotime($ebtime);
                $total_video_map['create_time'] = array('between',"$btime,$etime");   
                $grey_four = D('video_course')->where($total_video_map)->count();
                //购买数
                $order_map['a.create_time']=array('between',"$btime,$etime");
                $red_four = D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($order_map)->count();
                //第四天
                $bbtime=date('Y-m-d',strtotime("-3 day"));//前第四天
                $ebtime=date('Y-m-d',strtotime("-2 day"));//
                //这个时间查询以前是日期查询 不是时间戳  要改一下
                $btime=strtotime($bbtime);
                $etime=strtotime($ebtime);
                $total_video_map['create_time'] = array('between',"$btime,$etime");   
                $grey_three = D('video_course')->where($total_video_map)->count();
                //购买数
                $order_map['a.create_time']=array('between',"$btime,$etime");
                $red_three = D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($order_map)->count();
                //第三天
                $bbtime=date('Y-m-d',strtotime("-2 day"));//前第三天
                $ebtime=date('Y-m-d',strtotime("-1 day"));//
                //这个时间查询以前是日期查询 不是时间戳  要改一下
                $btime=strtotime($bbtime);
                $etime=strtotime($ebtime);
                $total_video_map['create_time'] = array('between',"$btime,$etime");   
                $grey_two = D('video_course')->where($total_video_map)->count();
                //购买数
                $order_map['a.create_time']=array('between',"$btime,$etime");
                $red_two = D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($order_map)->count();
                //昨天
                $bbtime=date('Y-m-d',strtotime("-1 day"));//昨天
                $ebtime=date('Y-m-d',time());//
                //这个时间查询以前是日期查询 不是时间戳  要改一下
                $btime=strtotime($bbtime);
                $etime=strtotime($ebtime);
                $total_video_map['create_time'] = array('between',"$btime,$etime");   
                $grey_one = D('video_course')->where($total_video_map)->count();
                //购买数
                $order_map['a.create_time']=array('between',"$btime,$etime");
                $red_one = D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($order_map)->count();
                //今天
                $bbtime=date('Y-m-d',time());//今天
                $ebtime=date('Y-m-d',strtotime("+1 day"));//明天
                //这个时间查询以前是日期查询 不是时间戳  要改一下
                $btime=strtotime($bbtime);
                $etime=strtotime($ebtime);
                $total_video_map['create_time'] = array('between',"$btime,$etime");   
                $grey_zero = D('video_course')->where($total_video_map)->count();
                //购买数
                $order_map['a.create_time']=array('between',"$btime,$etime");
                $red_zero = D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($order_map)->count();
                //连接起来
                $grey=$grey_six.','.$grey_five.','.$grey_four.','.$grey_three.','.$grey_two.','.$grey_one.','.$grey_zero;
                $red=$red_six.','.$red_five.','.$red_four.','.$red_three.','.$red_two.','.$red_one.','.$red_zero;
            }else{
                //直播 累计开播
                //第七天
                $bbtime=date('Y-m-d',strtotime("-6 day"));//前第七天
                $ebtime=date('Y-m-d',strtotime("-5 day"));//
                //这个时间查询以前是日期查询 不是时间戳  要改一下
                $btime=strtotime($bbtime);
                $etime=strtotime($ebtime); 
                $cumulative_live_map['create_time'] = array('between',"$btime,$etime");   
                $grey_six = D('live_course')->where($cumulative_live_map)->count();
                //预计开播  估计这个统计有问题
                $pre_live_map['create_time'] = array('between',"$btime,$etime");   
                $red_six = D('live_course')->where($pre_live_map)->count();
                //第六天
                $bbtime=date('Y-m-d',strtotime("-5 day"));//前第六天
                $ebtime=date('Y-m-d',strtotime("-4 day"));// 
                //这个时间查询以前是日期查询 不是时间戳  要改一下
                $btime=strtotime($bbtime);
                $etime=strtotime($ebtime);
                $cumulative_live_map['create_time'] = array('between',"$btime,$etime");   
                $grey_five = D('live_course')->where($cumulative_live_map)->count();
                //预计开播  估计这个统计有问题
                $pre_live_map['create_time'] = array('between',"$btime,$etime");   
                $red_five = D('live_course')->where($pre_live_map)->count();
                //第五天
                $bbtime=date('Y-m-d',strtotime("-4 day"));//前第五天
                $ebtime=date('Y-m-d',strtotime("-3 day"));// 
                //这个时间查询以前是日期查询 不是时间戳  要改一下
                $btime=strtotime($bbtime);
                $etime=strtotime($ebtime);
                $cumulative_live_map['create_time'] = array('between',"$btime,$etime");   
                $grey_four = D('live_course')->where($cumulative_live_map)->count();
                //预计开播  估计这个统计有问题
                $pre_live_map['create_time'] = array('between',"$btime,$etime");   
                $red_four = D('live_course')->where($pre_live_map)->count();
                //第四天
                $bbtime=date('Y-m-d',strtotime("-3 day"));//前第四天
                $ebtime=date('Y-m-d',strtotime("-2 day"));// 
                //这个时间查询以前是日期查询 不是时间戳  要改一下
                $btime=strtotime($bbtime);
                $etime=strtotime($ebtime);
                $cumulative_live_map['create_time'] = array('between',"$btime,$etime");   
                $grey_three = D('live_course')->where($cumulative_live_map)->count();
                //预计开播  估计这个统计有问题
                $pre_live_map['create_time'] = array('between',"$btime,$etime");   
                $red_three = D('live_course')->where($pre_live_map)->count();
                //第三天
                $bbtime=date('Y-m-d',strtotime("-2 day"));//前三天
                $ebtime=date('Y-m-d',strtotime("-1 day"));// 
                //这个时间查询以前是日期查询 不是时间戳  要改一下
                $btime=strtotime($bbtime);
                $etime=strtotime($ebtime);
                $cumulative_live_map['create_time'] = array('between',"$btime,$etime");   
                $grey_two = D('live_course')->where($cumulative_live_map)->count();
                //预计开播  估计这个统计有问题
                $pre_live_map['create_time'] = array('between',"$btime,$etime");   
                $red_two = D('live_course')->where($pre_live_map)->count();
                //昨天
                $bbtime=date('Y-m-d',strtotime("-1 day"));//昨天
                $ebtime=date('Y-m-d',time());//
                //这个时间查询以前是日期查询 不是时间戳  要改一下
                $btime=strtotime($bbtime);
                $etime=strtotime($ebtime);
                $cumulative_live_map['create_time'] = array('between',"$btime,$etime");   
                $grey_one = D('live_course')->where($cumulative_live_map)->count();
                //预计开播  估计这个统计有问题
                $pre_live_map['create_time'] = array('between',"$btime,$etime");   
                $red_one = D('live_course')->where($pre_live_map)->count();
                //今天
                $bbtime=date('Y-m-d',time());//今天
                $ebtime=date('Y-m-d',strtotime("+1 day"));//明天
                //这个时间查询以前是日期查询 不是时间戳  要改一下
                $btime=strtotime($bbtime);
                $etime=strtotime($ebtime);
                $cumulative_live_map['create_time'] = array('between',"$btime,$etime");   
                $grey_zero = D('live_course')->where($cumulative_live_map)->count();
                //预计开播  估计这个统计有问题
                $pre_live_map['create_time'] = array('between',"$btime,$etime");   
                $red_zero = D('live_course')->where($pre_live_map)->count();
                //连接起来
                $grey=$grey_six.','.$grey_five.','.$grey_four.','.$grey_three.','.$grey_two.','.$grey_one.','.$grey_zero;
                $red=$red_six.','.$red_five.','.$red_four.','.$red_three.','.$red_two.','.$red_one.','.$red_zero;
            }
            $this->assign('red',$red);
            $this->assign('grey',$grey);
        }else{
            //时间段查询
            // $where = " 1 = 1";
            $start_time = strtotime($_REQUEST['start_time']);
            $end_time = strtotime($_REQUEST['end_time']." 23:59:59");
            if(!empty($_REQUEST['start_time']) && !empty($_REQUEST['end_time'])){
                $where .= " and create_time >= {$start_time} and create_time <= {$end_time}";
                $this->assign('start_time',$_REQUEST['start_time']);
                $this->assign('end_time',$_REQUEST['end_time']);
            }else {
                if(!empty($_REQUEST['start_time'])){
                    $where .= " and create_time >= {$start_time}";
                    $this->assign('start_time',$_REQUEST['start_time']);
                }
                if(!empty($_REQUEST['end_time'])){
                    $where .= " and create_time <= {$end_time}";
                    $this->assign('end_time',$_REQUEST['end_time']);
                }
            }




        //开始时间 ~ 结束时间
        $start_date=I('start_time');
        $end_date=I('end_time');
//
        //如果为空，则从今天的0点为开始时间
        if(!empty($start_date))
            $start_date=date('Y-m-d',strtotime($start_date));
        else
            $start_date=date('Y-m-d',time());
//
        //如果为空，则以明天的0点为结束时间（不存在24:00:00，只会有00:00:00）
        if(!empty($end_date))
            $end_date=date('Y-m-d',strtotime($end_date));
        else
            $end_date=date('Y-m-d',strtotime('+1 day'));

        //between 查询 要求必须是从低到高
        if($start_date>$end_date)
        {
            $ttt=$start_date;
            $start_date=$end_date;
            $end_date=$ttt;
        }elseif($start_date==$end_date){
            echo '时间输入错误';die;
        }
        $time_s=strtotime($start_date);
        $time_e=strtotime($end_date);

        //生成中间时间点数组（时间戳格式、日期时间格式、日期序列）
        $days_inline_array=array();
        $times_inline_array=array();
        $days_list=array();
        //判断开始和结束时间是不是在同一天
        $days_inline_array[0]=$start_date;
        $times_inline_array[0]=$time_s;
        if(
            date('Y-m-d',$time_s)
            ==date('Y-m-d',$time_e)
        ){
            $days_inline_array[1]=$end_date;
            $times_inline_array[1]=$time_e;
            $days_list[]=date('Y-m-d',$time_s);
        }
        else
        {
            /**
             * A.取开始时间的第二天凌晨0点
             * B.用结束时间减去A
             * C.用B除86400取商，取余
             * D.用A按C的商循环+86400，取得分割时间点，如果C没有余数，则最后一个时间点与循环最后一个时间点一致
             */
            $A_temp=date('Y-m-d',$time_s+86400);
            $A=strtotime($A_temp);
            $B=$time_e-$A;
            $C_quotient=floor($B/86400);    //商舍去法取整
            $C_remainder=fmod($B,86400);               //余数

            $days_inline_array[1]=$A_temp;
            $times_inline_array[1]=$A;
            $days_list[]=date('Y-m-d',$A);
            for($increase_time=$A,$c_count_t=1;$c_count_t<=$C_quotient;$c_count_t++)
            {
                $increase_time+=86400;
                $days_inline_array[]=date('Y-m-d',$increase_time);
                $times_inline_array[]=$increase_time;
                $days_list[]=date('Y-m-d',$increase_time);
            }
            //如果有余数，则最后一个时间点大于循环最后一个时间点，但在同一天
            if($C_remainder)
            {
                $days_inline_array[]=$end_date;
                $times_inline_array[]=$time_e;
                //这里不再添加 $days_list，因为余数和最后一个凌晨0点必定是同一天
            }
        }

        // print_r($days_inline_array);die;
        foreach($days_inline_array as $k=>$v){
            if($k==0){
                $line_time=$v;
            }else{
                $line_time.=','.$v;
            }
            $btime=strtotime($v);
            $etime=$btime+86400;
            if($category==1){
                //面授课
                $class_map['create_time'] = array('between',"$btime,$etime");   
                $grey.=','. D('face_course')->where($class_map)->count();
                // print_r($red);die;
                //报名数
                $signup_map['a.create_time'] = array('between',"$btime,$etime");   
                $red.=','. D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($signup_map)->count();
                
            }elseif($category==2){
                //点播 总课程数

                $total_video_map['create_time'] = array('between',"$btime,$etime");   
                $grey .=','. D('video_course')->where($total_video_map)->count();
                //购买数
                $order_map['a.create_time']=array('between',"$btime,$etime");
                $red.=','. D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($order_map)->count();
                // print_r($grey);die;
            }else{
                //直播 累计开播
                $cumulative_live_map['create_time'] = array('between',"$btime,$etime");   
                $grey .=','. D('live_course')->where($cumulative_live_map)->count();
                //预计开播  估计这个统计有问题
                $pre_live_map['create_time'] = array('between',"$btime,$etime");   
                $red .=','. D('live_course')->where($pre_live_map)->count();
            }




        }

        $grey=substr($grey, 1);
        
        $red=substr($red, 1);
        $this->assign('grey',$grey);
        $this->assign('red',$red);
        $this->assign('line_time',$line_time);










        }


        

        $this->assign('cur','内容统计');
        $this->display();
    }
    /**
     * Mr.Jiang
     * 内容统计 废弃
     */
    public function contentStatistics123()
    {
        $iid = $_REQUEST['iid'];
        //直播课统计，累计开播、预开播
        $cumulative_live_map['status'] = array(array('eq', 2), array('eq', 3), 'OR');
        $cumulative_live_map['is_del'] = array('eq', 0);
        $cumulative_live_map['iid'] = array('eq', $iid);
        $cumulative = D('live_course')->where($cumulative_live_map)->count();
        $this->assign('cumulative', $cumulative);

        $pre_live_map['status'] = array('eq', 1);
        $pre_live_map['is_del'] = array('eq', 0);
        $pre_live_map['iid'] = array('eq', $iid);
        $pre = D('live_course')->where($pre_live_map)->count();
        $this->assign('pre', $pre);

        //点播课统计，总课程数、购买数
        $total_video_map['is_del'] = array('eq', 0);
        $total_video_map['is_upper'] = array('eq', 1);
        $total_video_map['iid'] = array('eq', $iid);
        $total = D('video_course')->where($total_video_map)->count();
        $this->assign('total', $total);

        $order_map['a.status'] = array('eq', 4);
        $order_map['a.iid'] = array('eq', $iid);
        $order_map['a.type'] = array('eq', 3);
        $order = D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($order_map)->count();
        $this->assign('order', $order);

        //面授课统计，开课数、报名数
        $class_map['iid'] = array('eq', $iid);
        $class_map['status'] = array('eq', 2);
        $class_map['is_upper'] = array('eq', 1);
        $class_map['is_del'] = array('eq', 0);
        $class = D('face_course')->where($class_map)->count();
        $this->assign('class', $class);

        $signup_map['a.status'] = array('eq', 4);
        $signup_map['a.iid'] = array('eq', $iid);
        $signup_map['a.type'] = array('eq', 2);
        $signup = D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($signup_map)->count();
        $this->assign('signup', $signup);

        //折线图统计



        $search=$_REQUEST['search']?$_REQUEST['search']:1;
        $_REQUEST['category']?$category=$_REQUEST['category']:$category=1;
        $this->assign('category',$category);
        $this->assign('search',$search);

        if($search==1){
            //今天
            $line_time = date('m-d',time());
            $this->assign('line_time',$line_time);

            //开课数
            $btime=date('m-d',time());//今天
            $etime=date('m-d',strtotime("+1 day"));//明天
            if($category==1){
                //面授课
                $class_map['create_time'] = array('between',"$btime,$etime");   
                $grey= D('face_course')->where($class_map)->count();
                // print_r($red);die;
                //报名数
                $signup_map['a.create_time'] = array('between',"$btime,$etime");   
                $red= D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($signup_map)->count();
                
            }elseif($category==2){
                //点播 总课程数

                $total_video_map['create_time'] = array('between',"$btime,$etime");   
                $grey = D('video_course')->where($total_video_map)->count();
                //购买数
                $order_map['a.create_time']=array('between',"$btime,$etime");
                $red = D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($order_map)->count();
                // print_r($grey);die;
            }else{
                //直播 累计开播
                $cumulative_live_map['create_time'] = array('between',"$btime,$etime");   
                $grey = D('live_course')->where($cumulative_live_map)->count();
                //预计开播  估计这个统计有问题
                $pre_live_map['create_time'] = array('between',"$btime,$etime");   
                $red = D('live_course')->where($pre_live_map)->count();
            }
                            // print_r($red);die;
            $this->assign('red',$red);
            $this->assign('grey',$grey);
        }elseif($search==2){
            //昨天
            $line_time = date('m-d',strtotime("-1 day"));
            $this->assign('line_time',$line_time);


            //开课数
            $btime=date('m-d',strtotime("-1 day"));//昨天
            $etime=date('m-d',time());//今天
            
            if($category==1){
                //面授课
                $class_map['create_time'] = array('between',"$btime,$etime");   
                $grey= D('face_course')->where($class_map)->count();
                // print_r($red);die;
                //报名数
                $signup_map['a.create_time'] = array('between',"$btime,$etime");   
                $red= D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($signup_map)->count();
                // print_r($grey);die;
            }elseif($category==2){
                //点播 总课程数
                $total_video_map['create_time'] = array('between',"$btime,$etime");   
                $grey = D('video_course')->where($total_video_map)->count();
                //购买数
                $order_map['a.create_time']=array('between',"$btime,$etime");
                $red = D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($order_map)->count();
            }else{
                //直播 累计开播
                $cumulative_live_map['create_time'] = array('between',"$btime,$etime");   
                $grey = D('live_course')->where($cumulative_live_map)->count();
                //预计开播  估计这个统计有问题
                $pre_live_map['create_time'] = array('between',"$btime,$etime");   
                $red = D('live_course')->where($pre_live_map)->count();
            }
            $this->assign('red',$red);
            $this->assign('grey',$grey);
        }elseif($search==3){
            //最近七天
            $line_time = date('m-d',strtotime("-6 day"));
            $line_time .= ",".date('m-d',strtotime("-5 day"));
            $line_time .= ",".date('m-d',strtotime("-4 day"));
            $line_time .= ",".date('m-d',strtotime("-3 day"));
            $line_time .= ",".date('m-d',strtotime("-2 day"));
            $line_time .= ",".date('m-d',strtotime("-1 day"));
            $line_time .= ",".date('m-d',time());
            $this->assign('line_time',$line_time);


            if($category==1){
                //面授课
                //第七天
                $btime=date('m-d',strtotime("-6 day"));//前第七天
                $etime=date('m-d',strtotime("-5 day"));//
                $class_map['create_time'] = array('between',"$btime,$etime");   
                $grey_six= D('face_course')->where($class_map)->count();
                //报名数
                $signup_map['a.create_time'] = array('between',"$btime,$etime");   
                $red_six= D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($signup_map)->count();
                //第六天
                $btime=date('m-d',strtotime("-5 day"));//前第六天
                $etime=date('m-d',strtotime("-4 day"));//
                $class_map['create_time'] = array('between',"$btime,$etime");   
                $grey_five= D('face_course')->where($class_map)->count();
                //报名数
                $signup_map['a.create_time'] = array('between',"$btime,$etime");   
                $red_five= D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($signup_map)->count();
                //第五天
                $btime=date('m-d',strtotime("-4 day"));//前第五天
                $etime=date('m-d',strtotime("-3 day"));//
                $class_map['create_time'] = array('between',"$btime,$etime");   
                $grey_four= D('face_course')->where($class_map)->count();
                //报名数
                $signup_map['a.create_time'] = array('between',"$btime,$etime");   
                $red_four= D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($signup_map)->count();
                //第四天
                $btime=date('m-d',strtotime("-3 day"));//前第四天
                $etime=date('m-d',strtotime("-2 day"));//
                $class_map['create_time'] = array('between',"$btime,$etime");   
                $grey_three= D('face_course')->where($class_map)->count();
                //报名数
                $signup_map['a.create_time'] = array('between',"$btime,$etime");   
                $red_three= D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($signup_map)->count();
                //第三天
                $btime=date('m-d',strtotime("-2 day"));//前第三天
                $etime=date('m-d',strtotime("-1 day"));//
                $class_map['create_time'] = array('between',"$btime,$etime");   
                $grey_two= D('face_course')->where($class_map)->count();
                //报名数
                $signup_map['a.create_time'] = array('between',"$btime,$etime");   
                $red_two= D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($signup_map)->count();
                //第二天
                $btime=date('m-d',strtotime("-1 day"));//昨天
                $etime=date('m-d',time());//
                $class_map['create_time'] = array('between',"$btime,$etime");   
                $grey_one= D('face_course')->where($class_map)->count();
                //报名数
                $signup_map['a.create_time'] = array('between',"$btime,$etime");   
                $red_one= D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($signup_map)->count();
                //今天
                $btime=date('m-d',time());//今天
                $etime=date('m-d',strtotime("+1 day"));//明天
                $class_map['create_time'] = array('between',"$btime,$etime");   
                $grey_zero= D('face_course')->where($class_map)->count();
                //报名数
                $signup_map['a.create_time'] = array('between',"$btime,$etime");   
                $red_zero= D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($signup_map)->count();

                //连接起来
                $grey=$grey_six.','.$grey_five.','.$grey_four.','.$grey_three.','.$grey_two.','.$grey_one.','.$grey_zero;
                $red=$red_six.','.$red_five.','.$red_four.','.$red_three.','.$red_two.','.$red_one.','.$red_zero;

            }elseif($category==2){
                //点播 总课程数
                //第七天
                $btime=date('m-d',strtotime("-6 day"));//前第七天
                $etime=date('m-d',strtotime("-5 day"));//
                $total_video_map['create_time'] = array('between',"$btime,$etime");   
                $grey_six = D('video_course')->where($total_video_map)->count();
                //购买数
                $order_map['a.create_time']=array('between',"$btime,$etime");
                $red_six = D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($order_map)->count();
                //第六天
                $btime=date('m-d',strtotime("-5 day"));//前第六天
                $etime=date('m-d',strtotime("-4 day"));//
                $total_video_map['create_time'] = array('between',"$btime,$etime");   
                $grey_five = D('video_course')->where($total_video_map)->count();
                //购买数
                $order_map['a.create_time']=array('between',"$btime,$etime");
                $red_five = D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($order_map)->count();
                //第五天
                $btime=date('m-d',strtotime("-4 day"));//前第五天
                $etime=date('m-d',strtotime("-3 day"));//
                $total_video_map['create_time'] = array('between',"$btime,$etime");   
                $grey_four = D('video_course')->where($total_video_map)->count();
                //购买数
                $order_map['a.create_time']=array('between',"$btime,$etime");
                $red_four = D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($order_map)->count();
                //第四天
                $btime=date('m-d',strtotime("-3 day"));//前第四天
                $etime=date('m-d',strtotime("-2 day"));//
                $total_video_map['create_time'] = array('between',"$btime,$etime");   
                $grey_three = D('video_course')->where($total_video_map)->count();
                //购买数
                $order_map['a.create_time']=array('between',"$btime,$etime");
                $red_three = D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($order_map)->count();
                //第三天
                $btime=date('m-d',strtotime("-2 day"));//前第三天
                $etime=date('m-d',strtotime("-1 day"));//
                $total_video_map['create_time'] = array('between',"$btime,$etime");   
                $grey_two = D('video_course')->where($total_video_map)->count();
                //购买数
                $order_map['a.create_time']=array('between',"$btime,$etime");
                $red_two = D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($order_map)->count();
                //昨天
                $btime=date('m-d',strtotime("-1 day"));//昨天
                $etime=date('m-d',time());//
                $total_video_map['create_time'] = array('between',"$btime,$etime");   
                $grey_one = D('video_course')->where($total_video_map)->count();
                //购买数
                $order_map['a.create_time']=array('between',"$btime,$etime");
                $red_one = D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($order_map)->count();
                //今天
                $btime=date('m-d',time());//今天
                $etime=date('m-d',strtotime("+1 day"));//明天
                $total_video_map['create_time'] = array('between',"$btime,$etime");   
                $grey_zero = D('video_course')->where($total_video_map)->count();
                //购买数
                $order_map['a.create_time']=array('between',"$btime,$etime");
                $red_zero = D('order a')->join('left join teach_vice_order b on a.id = b.order_id')->where($order_map)->count();
                //连接起来
                $grey=$grey_six.','.$grey_five.','.$grey_four.','.$grey_three.','.$grey_two.','.$grey_one.','.$grey_zero;
                $red=$red_six.','.$red_five.','.$red_four.','.$red_three.','.$red_two.','.$red_one.','.$red_zero;
            }else{
                //直播 累计开播
                //第七天
                $btime=date('m-d',strtotime("-6 day"));//前第七天
                $etime=date('m-d',strtotime("-5 day"));// 
                $cumulative_live_map['create_time'] = array('between',"$btime,$etime");   
                $grey_six = D('live_course')->where($cumulative_live_map)->count();
                //预计开播  估计这个统计有问题
                $pre_live_map['create_time'] = array('between',"$btime,$etime");   
                $red_six = D('live_course')->where($pre_live_map)->count();
                //第六天
                $btime=date('m-d',strtotime("-5 day"));//前第六天
                $etime=date('m-d',strtotime("-4 day"));// 
                $cumulative_live_map['create_time'] = array('between',"$btime,$etime");   
                $grey_five = D('live_course')->where($cumulative_live_map)->count();
                //预计开播  估计这个统计有问题
                $pre_live_map['create_time'] = array('between',"$btime,$etime");   
                $red_five = D('live_course')->where($pre_live_map)->count();
                //第五天
                $btime=date('m-d',strtotime("-4 day"));//前第五天
                $etime=date('m-d',strtotime("-3 day"));// 
                $cumulative_live_map['create_time'] = array('between',"$btime,$etime");   
                $grey_four = D('live_course')->where($cumulative_live_map)->count();
                //预计开播  估计这个统计有问题
                $pre_live_map['create_time'] = array('between',"$btime,$etime");   
                $red_four = D('live_course')->where($pre_live_map)->count();
                //第四天
                $btime=date('m-d',strtotime("-3 day"));//前第四天
                $etime=date('m-d',strtotime("-2 day"));// 
                $cumulative_live_map['create_time'] = array('between',"$btime,$etime");   
                $grey_three = D('live_course')->where($cumulative_live_map)->count();
                //预计开播  估计这个统计有问题
                $pre_live_map['create_time'] = array('between',"$btime,$etime");   
                $red_three = D('live_course')->where($pre_live_map)->count();
                //第三天
                $btime=date('m-d',strtotime("-2 day"));//前三天
                $etime=date('m-d',strtotime("-1 day"));// 
                $cumulative_live_map['create_time'] = array('between',"$btime,$etime");   
                $grey_two = D('live_course')->where($cumulative_live_map)->count();
                //预计开播  估计这个统计有问题
                $pre_live_map['create_time'] = array('between',"$btime,$etime");   
                $red_two = D('live_course')->where($pre_live_map)->count();
                //昨天
                $btime=date('m-d',strtotime("-1 day"));//昨天
                $etime=date('m-d',time());//
                $cumulative_live_map['create_time'] = array('between',"$btime,$etime");   
                $grey_one = D('live_course')->where($cumulative_live_map)->count();
                //预计开播  估计这个统计有问题
                $pre_live_map['create_time'] = array('between',"$btime,$etime");   
                $red_one = D('live_course')->where($pre_live_map)->count();
                //今天
                $btime=date('m-d',time());//今天
                $etime=date('m-d',strtotime("+1 day"));//明天
                $cumulative_live_map['create_time'] = array('between',"$btime,$etime");   
                $grey_zero = D('live_course')->where($cumulative_live_map)->count();
                //预计开播  估计这个统计有问题
                $pre_live_map['create_time'] = array('between',"$btime,$etime");   
                $red_zero = D('live_course')->where($pre_live_map)->count();
                //连接起来
                $grey=$grey_six.','.$grey_five.','.$grey_four.','.$grey_three.','.$grey_two.','.$grey_one.','.$grey_zero;
                $red=$red_six.','.$red_five.','.$red_four.','.$red_three.','.$red_two.','.$red_one.','.$red_zero;
            }
            $this->assign('red',$red);
            $this->assign('grey',$grey);
        }else{
            //时间段查询
            $where = " 1 = 1";
            $start_time = strtotime($_REQUEST['start_time']);
            $end_time = strtotime($_REQUEST['end_time']." 23:59:59");
            if(!empty($_REQUEST['start_time']) && !empty($_REQUEST['end_time'])){
                $where .= " and create_time >= {$start_time} and create_time <= {$end_time}";
                $this->assign('start_time',$_REQUEST['start_time']);
                $this->assign('end_time',$_REQUEST['end_time']);
            }else {
                if(!empty($_REQUEST['start_time'])){
                    $where .= " and create_time >= {$start_time}";
                    $this->assign('start_time',$_REQUEST['start_time']);
                }
                if(!empty($_REQUEST['end_time'])){
                    $where .= " and create_time <= {$end_time}";
                    $this->assign('end_time',$_REQUEST['end_time']);
                }
            }

            //根据时间段我有疑问  有两个时间怎么整
            if($category==1){
                //面授课

                $line_list = D()->query("select count(*) as `count`,FROM_UNIXTIME(create_time,'%Y%-%m%-%d') as create_time from teach_face_course where {$where} group by FROM_UNIXTIME(create_time,'%Y%m%d') order by create_time asc");
            }elseif($category==2){
                //点播 总课程数
 
                $line_list = D()->query("select count(*) as `count`,FROM_UNIXTIME(create_time,'%Y%-%m%-%d') as create_time from teach_video_course where {$where} group by FROM_UNIXTIME(create_time,'%Y%m%d') order by create_time asc");

            }else{
                //直播 累计开播
                $line_list = D()->query("select count(*) as `count`,FROM_UNIXTIME(create_time,'%Y%-%m%-%d') as create_time from teach_live_course where {$where} group by FROM_UNIXTIME(create_time,'%Y%m%d') order by create_time asc");
                //预计开播  估计这个统计有问题

            }

            $line_time = "";
            $grey = "";
            foreach ($line_list as $key=>$item) {
                $line_time .= $item['create_time'].",";
                $grey .= $item['count'].",";
            }
            $line_time = mb_substr($line_time,0,mb_strlen($line_time,'UTF-8')-1,'UTF-8');
            $this->assign('line_time',$line_time);

            $grey = mb_substr($grey,0,mb_strlen($grey,'UTF-8')-1,'UTF-8');
            $this->assign('grey',$grey);



        }


        

        $this->assign('cur','内容统计');
        $this->display();
    }

    public function uploadImg() {
        if (empty($_FILES) ){
            echo json_encode(['code'=>1,'msg'=>'图片不能为空']);exit;
        }else{
            $file = $_FILES['image'];
            if (!is_dir("Uploads/" . date("Y-m-d"))) {
                mkdir("Uploads/" . date("Y-m-d"));
            }
            if (is_uploaded_file($file['tmp_name'])) {

                $str = stristr($file['name'], '.');
                $str=substr($str,1);
                $avatar_path = "Uploads/" . date("Y-m-d") . "/" . time() . rand(1000,9999) . '.' . $str;

                if(copy($file['tmp_name'],$avatar_path)){
// print_r($file['tmp_name']);die;
                    $game_path = str_replace('Uploads/','game/headimage/',$avatar_path);
                    copy($file['tmp_name'],$game_path);
                    $cover['path'] = "/".$avatar_path;
                    $cover['status'] = 1;
                    $cover['create_time'] = time();
                    $re = M('picture')->add($cover);
                    if($re){
                        $img=get_host() . get_cover($re, "path");
                        $hh['imgurl']=$img;
                        $hh['imgid']=$re;
                        echo json_encode(['code'=>0,'msg'=>'成功','info'=>$hh]);exit;
                    }else{
                        echo json_encode(['code'=>1,'msg'=>'失败']);exit;
                    }
                }else {
                    echo json_encode(['code'=>1,'msg'=>'失败']);exit;
                }
            }
        }
    }
}